﻿//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Media.Imaging;
using Microsoft.WindowsAPICodePack.Shell;

namespace Microsoft.LibraryManagerDemo.Models
{
    /// <summary>
    /// Represents a shell library model.
    /// </summary>
    public class Library : Model
    {
        #region Fields

        private string _defaultSaveFolder;
        private BitmapSource _shellIcon;
        private bool _isPinnedToNavigationPane;
        private LibraryFolderType _folderType;
 
        #endregion

        #region Static

        /// <summary>
        /// Null library instance
        /// </summary>
        public static readonly Library Null = new Library(string.Empty);

        #endregion

        #region Properties

        /// <summary>
        /// Gets a value to indicate whether this library has no folders
        /// </summary>
        public bool IsEmpty
        {
            get { return InternalFolders.Count == 0; }
        }

        /// <summary>
        /// Gets list of folders attached with the library
        /// </summary>
        public IEnumerable<Folder> Folders
        {
            get { return InternalFolders; }
        }

        /// <summary>
        /// Gets or sets the library name 
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Gets or sets the default save folder
        /// </summary>
        public string DefaultSaveFolder
        {
            get { return _defaultSaveFolder; }
            set
            {
                if (value != _defaultSaveFolder)
                {
                    _defaultSaveFolder = value;
                    NotifyPropertyChanged("DefaultSaveFolder");
                }
            }
        }

        /// <summary>
        /// Gets or sets the library icon
        /// </summary>
        public BitmapSource ShellIcon
        {
            get { return _shellIcon; }
            set
            {
                if (value != _shellIcon)
                {
                    _shellIcon = value;
                    NotifyPropertyChanged("ShellIcon");
                }
            }
        }

        /// <summary>
        /// Gets or sets the pinned To Explorer navigation pane state
        /// </summary>
        public bool IsPinnedToNavigationPane
        {
            get { return _isPinnedToNavigationPane; }
            set
            {
                if (value != _isPinnedToNavigationPane)
                {
                    _isPinnedToNavigationPane = value;
                    NotifyPropertyChanged("IsPinnedToNavigationPane");
                }
            }
        }

        /// <summary>
        /// Gets or sets the folder type template
        /// </summary>
        public LibraryFolderType FolderType
        {
            get { return _folderType; }
            set
            {
                if (value != _folderType)
                {
                    _folderType = value;
                    NotifyPropertyChanged("FolderType");
                }
            }
        }

        private ObservableCollection<Folder> InternalFolders { get; set; }

        #endregion

        #region Initializers

        /// <summary>
        /// Initializes a new instance of this type.
        /// </summary>
        /// <param name="name">The name of the library.</param>
        public Library(string name)
        {
            this.Name = name;
            this.InternalFolders = new ObservableCollection<Folder>();
        }

        #endregion

        #region Operation

        /// <summary>
        /// Add a folder to the library.
        /// </summary>
        /// <param name="folder">The folder to add.</param>
        public void AddFolder(Folder folder)
        {
            InternalFolders.Add(folder);
        }

        /// <summary>
        /// Remove a folder from the library.
        /// </summary>
        /// <param name="folder">The folder to remove.</param>
        public void RemoveFolder(Folder folder)
        {
            InternalFolders.Remove(folder);
        }

        #endregion
    }
}
